<template>
  <div>
    <div v-if="!pushStatus">
    <el-row style="margin-bottom:10px">
      <el-col :span="8" >
        <h4 style="margin:0">
          <span>活动审核</span>
        </h4>
      </el-col>
      <el-col :span="16" style="text-align:right">
        
      </el-col>
    </el-row>
   
    <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55"></el-table-column>-->
      <el-table-column prop="ID" label="序号" width="60">
         <template slot-scope="scope">{{scope.$index+1}}</template>
      </el-table-column>
      <el-table-column prop="date" label="活动信息">
        <template slot-scope="scope">
          <div>
            <div>{{timeFun(scope.row.created_at)}} </div>
            <div>公司：{{scope.row.hospital_name}}</div>
            <div>活动：{{scope.row.name}}</div>
            <div>时间：{{timeFun(scope.row.begin_time)}} 至 {{timeFun(scope.row.end_time)}}</div>
            <div>地址：{{scope.row.positaion}}</div>
          </div>
        </template>
      </el-table-column>      
      <el-table-column prop="tui" label="内容">
        <template slot-scope="scope">
          <div>
            <div>活动链接：{{scope.row.link_url}}</div>
            <div style="display:flex;align-items: center;"><span>封面：</span> <img :src="scope.row.logo_url" @click="showImage(srcFun(scope.row.cover))" style="margin-right:5px;margin-top:10px;width:70px;height:80px" alt=""></div>
            <div>
              <span>活动内容：</span><el-button class="addBtn" @click="seachInfo(scope.row)" type="primary">内容详情</el-button>
              <!-- <div v-html="scope.row.content"></div> -->
            </div>
            <div>
              <span  v-for="(item,index) in scope.row.files" :key="index" style="padding-right:10px">
                <a :href="item" >{{fileName(item)}}</a>
              </span>
              
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0 "> 待审核</span>
          <span v-else-if="scope.row.status == 1 "> 审核通过</span>
          <span v-else-if="scope.row.status == 2 " style="color:red"> 审核失败</span>
        </template>
      </el-table-column>
      <el-table-column width="150" label="操作">
        <template slot-scope="scope">
          <div v-if="userRole.HPT_AC_1706003" >
            <el-button class="addBtn" type="primary" @click="seachFun(scope.row)">查看</el-button>
            <el-button class="addBtn" v-if="scope.row.status == 0 " @click="passActiveFun(scope.row.id)" type="success">通过</el-button>
            <!-- <el-button class="addBtn" >下载附件</el-button> -->
          </div>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="内容" :visible.sync="dialogVisible" center width="40%" :before-close="handleClose">
        <div v-html="contentBox">

        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="passActiveFun(passId)">通过</el-button>
        </span>
      </el-dialog>

    <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
    </div>
    </div>
     <div v-if="pushStatus">
       <Seachactivity   @getlist="getlist" ref="artice" :editData="editData"></Seachactivity>
    </div>
    <el-dialog :visible.sync="showSta">
      <img width="100%" :src="showImgeUrl" alt="">
    </el-dialog>
  </div>
</template>

<script>
  import Seachactivity from './Activitem/Seachactivity'
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'
  export default {
    data() {
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        pushStatus:false,
        dialogVisible: false,
        editData:'',
        contentBox:'',
        passId:'',
        total:0,
        currentPage4: 1,//分野  
        page:1,
        pageSize:10,
        tableData: [],
        showSta:false,
        showImgeUrl:'',
      }
    },
    components:{
      Seachactivity
    },
    created(){
      this.getlist()
    },
    methods: {
      getlist(){
        Http.getActivAuditslList({
          "pageIndex":this.page,
          "pageSize":this.pageSize,
          "status":1
        })
         .then( res => {
          this.tableData = res.data.data.rows;
          this.total = res.data.data.total;
        })
        .catch( error => {
          
        })
        this.pushStatus = false;
      },
      timeFun(row) {
        return getTime(row)
      },

      fileName(val) {
        const arr = val.split('http://pdi2rfi8n.bkt.clouddn.com/')
        return arr[1]
      },
      showImage(row){
        this.showSta = true;
        this.showImgeUrl = row
      },
      seachFun(row) {
        
        this.pushStatus = true;
        this.editData = row;
      },
      passActiveFun(row) {
        const obj = {
          "id":row,
          "status":1
        };
        Http.AuditActive(obj)
        .then( res => {
          
           if( res.data.code == 200 ){
            this.$message.success('审核成功')
            this.getlist()         
          } else if(res.data.code == -1003) {
            this.$message.error(`请求失败原因：${res.data.message}`)
            this.$router.push('/')
          } else {
             this.$message.error('审核失败')
          }
        })
        .catch( error => {
          this.$message.error('服务器请求失败')
        })
      },
      seachInfo(row) {
        this.contentBox = row.content;
        this.passId = row.id
        this.dialogVisible = true;
      },
      handleClose(done) {
        this.dialogVisible = false;
        this.contentBox = '';
      },
      //选择 推荐
      handleSelectionChange() {},
       //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getlist()
        
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getlist()
        
      },
    }
  }
</script>
<style  scoped>
.box{
  border-bottom:1px solid red;
}
    .test{
        border:1px solid #ccc;
    }
    .drag-item{
        width: 200px;
        height: 50px;
        line-height: 50px;
        margin: auto;
        position: relative;
        
        background: #ddd;
        margin:20px 5px;
    }
    .ghostClass{
        opacity: 1;
    }
    .bottom{
        width: 200px;
        height: 50px;
        position: relative;
        background: blue;
        top:2px;
        left: 2px;
        transition: all .5s linear;
    }
</style>
